﻿using System;
using System.Windows.Forms;

namespace Storm.TextEditor.Editor.Forms
{
	/// <summary>
	/// Represents the Go To Line dialog of a TextEditor.
	/// </summary>
	public partial class GotoLine
		: Form
	{
		#region Fields

		private TextEditorBase owner = null;

		#endregion

		#region Methods

		#region EventHandlers

		private void btnOK_Click(object sender, EventArgs e)
		{
			try
			{
				int rowIndex = int.Parse(txtRow.Text) - 1;
				owner.GotoLine(rowIndex);
			}
			catch { }

			this.Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void GotoLine_Activated(object sender, EventArgs e)
		{
			txtRow.Focus();
		}

		#endregion

		#endregion

		/// <summary>
		/// Initializes a new instance of GotoLine.
		/// </summary>
		public GotoLine()
		{
			// Required by the Windows Forms Designer.
			InitializeComponent();
		}

		/// <summary>
		/// Initializes a new instance of GotoLine.
		/// </summary>
		/// <param name="Owner">TextEditorBase control that will be the FindReplace's parent.</param>
		/// <param name="rowCount">The number of rows in the parent TextEditor.</param>
		public GotoLine(TextEditorBase Owner, int rowCount)
		{
			// Required by the Windows Forms Designer.
			InitializeComponent();

			lblLines.Text = "Line number (1-" + (rowCount).ToString() + "):";
			owner = Owner;
		}
	}
}
